import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import '../../../app_files.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    BannerComponentState state, Dispatch dispatch, ViewService viewService) {
  double rpx = double.tryParse((MediaQuery.of(viewService.context).size.width / 375).toStringAsFixed(2));
  Widget _widget = state.list.length > 0
      ? Container(
          height: 140*rpx,
          width: ScreenUtil.screenWidthDp,
          margin: EdgeInsets.only(left: 15,right: 15),
          child: Theme(
            data: ThemeData(
                primaryColor: ThemeConfig.rgba(78, 130, 239, 1), //用于导航栏、FloatingActionButton//用于Icon颜色
            ),
            child: Swiper(
              itemBuilder: (BuildContext context, int index) {
                String imgUrl = state.list[index].imgUrl;
                return ClipRRect(
                borderRadius: BorderRadius.circular(6),
                  child: InkWell(
                    onTap: () {
                      dispatch(
                          BannerComponentActionCreator.onTap(state.list[index]));
                    },
//                    child: Image.network(
//                      NetworkConfig.imageurl(imgUrl),
//                      fit: BoxFit.fill,
//                    ),
                  child: Image.asset('images/banner.png',fit: BoxFit.fill,),
                  ),
                );
              },
              itemCount: state.list.length,
              pagination:  SwiperPagination(),
              autoplay: false,
              autoplayDelay: 5000,
              viewportFraction: 1,
              scale: 1,
            ),
          ),
        )
      : Container(
          child: Center(
            child: SpinKitCircle(color: ThemeConfig.mainColor),
          ),
        );
  return _widget;
}
